package com.hougong.im.test;

import java.io.*;
import java.util.Iterator;

public class MyIterator<T> implements Iterable<T>,Iterator<T> {
    private BufferedReader br;
    private int index=0;
    private String line;
    public MyIterator() throws FileNotFoundException {
        FileReader fis=new FileReader("E:\\MyOpenSource\\hougong\\im\\src\\main\\resources\\a.data");
        br=new BufferedReader(fis);
    }

    @Override
    public Iterator<T> iterator() {
        index=0;
        return this;
    }

    @Override
    public boolean hasNext() {
        try {
          line= br.readLine();
          if(line!=null){
              return true;
          }else {
              br.close();
              return false;
          }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public T next() {
        if(line!=null){
            return (T) line;
        }
        throw new RuntimeException("没有下一个了");
    }
}
